package cn.itsource.config;

import cn.dev33.satoken.stp.StpInterface;
import cn.itsource.constants.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义权限验证接口扩展 
 */

@Slf4j
public class GatewayStpInterfaceImpl implements StpInterface {

    private RedisTemplate<String, Object> redisTemplate;

    public GatewayStpInterfaceImpl(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        // 返回此 loginId 拥有的权限列表
        //获取redis中的权限列表
        String permissionsId = String.format(Constants.Redis.PERMISSIONS_ID, loginId);
        List<String> list = (List<String>) redisTemplate.opsForValue().get(permissionsId);
        log.info("权限列表 - {}",list);
        return list;
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        // 返回此 loginId 拥有的角色列表
        return null;
    }

}
